if orders and not orders.ActivatedStopTransaction then


function orders:ActivatedStopTransaction(template)
	if template.ex__.stop_qty then template.qty__ = template.ex__.stop_qty end
	
	local transaction = self:NewTransaction(template, {
		--ex__ = template.ex__,
		ACTION = "NEW_STOP_ORDER",
		STOP_ORDER_KIND = "ACTIVATED_BY_ORDER_SIMPLE_STOP_ORDER",
		BASE_ORDER_KEY = template.BASE_ORDER_KEY or template.ex__.co_order_num or template.ex__.key,
		ACTIVATE_IF_BASE_ORDER_PARTLY_FILLED = "yes",
		USE_BASE_ORDER_BALANCE = "yes",
		OFFSET_UNITS = "PRICE_UNITS",
		--QUANTITY = template.QUANTITY,
		--EXPIRY_DATE = "TODAY",
		--SECCODE = template.SECCODE,
		--CLASSCODE = template.CLASSCODE,
		--CLIENT_CODE = template.CLIENT_CODE,
		--ACCOUNT = template.ACCOUNT,
	})
	
	if not transaction then return end
	
	transaction.BASE_ORDER_KEY = tostring(transaction.BASE_ORDER_KEY)
	if template.OPERATION then
		if template.OPERATION == "B" then
			transaction.OPERATION = "S"
		else
			transaction.OPERATION = "B"
		end
	elseif bit.test(template.ex__.flags, 2) then
		transaction.OPERATION = "S"
	else
		transaction.OPERATION = "B"
	end
	
	local p = template.ex__.sl
	if not p then p = template.ex__.condition_price end
	transaction.STOPPRICE = lib:FormatPrice(p, template.ex__.instrument)
	
	p = template.ex__.price
	if not p then p = 3 * template.ex__.sl - 2 * template.ex__.lm end
	transaction.PRICE = lib:FormatPrice(p, template.ex__.instrument)
	
	self.log("ActivatedStopTransaction", transaction)

	return transaction
end


function orders:ActivatedTakeStopTransaction(template)
	if template.ex__.stop_qty then template.qty__ = template.ex__.stop_qty end
	
	local transaction = self:NewTransaction(template, {
		--ex__ = template.ex__,
		ACTION = "NEW_STOP_ORDER",
		STOP_ORDER_KIND = "ACTIVATED_BY_ORDER_TAKE_PROFIT_AND_STOP_LIMIT_ORDER",
		BASE_ORDER_KEY = template.BASE_ORDER_KEY or template.ex__.co_order_num or template.ex__.key,
		ACTIVATE_IF_BASE_ORDER_PARTLY_FILLED = "yes",
		USE_BASE_ORDER_BALANCE = "yes",
		MARKET_TAKE_PROFIT = "no",
		MARKET_STOP_LIMIT = "yes",
		OFFSET = "0",
		OFFSET_UNITS = "PRICE_UNITS",
		SPREAD = "0",
		SPREAD_UNITS = "PRICE_UNITS",
		--QUANTITY = template.QUANTITY,
		--EXPIRY_DATE = "TODAY",
		--SECCODE = template.SECCODE,
		--CLASSCODE = template.CLASSCODE,
		--CLIENT_CODE = template.CLIENT_CODE,
		--ACCOUNT = template.ACCOUNT,
	})
	
	if not transaction then return end
	
	transaction.BASE_ORDER_KEY = tostring(transaction.BASE_ORDER_KEY)
	if template.OPERATION then
		if template.OPERATION == "B" then
			transaction.OPERATION = "S"
		else
			transaction.OPERATION = "B"
		end
	elseif bit.test(template.ex__.flags, 2) then
		transaction.OPERATION = "S"
	else
		transaction.OPERATION = "B"
	end
	--transaction.PRICE = nil
	
	local p = template.ex__.tp
	if not p then p = template.ex__.condition_price end
	transaction.STOPPRICE = lib:FormatPrice(p, template.ex__.instrument)
	
	p = template.ex__.sl
	if not p then p = template.ex__.condition_price2 end
	transaction.STOPPRICE2 = lib:FormatPrice(p, template.ex__.instrument)
		
	self.log("ActivatedTakeStopTransaction", transaction)
	
	return transaction
end


function orders:SendActivatedStop(transaction, next_transaction)
    self.log("SendActivatedStop")
	return self:sendTransaction(self:ActivatedStopTransaction(transaction), next_transaction)
end


function orders:SendActivatedTakeStop(transaction, next_transaction)
	self.log("SendActivatedTakeStop")
	return self:sendTransaction(self:ActivatedTakeStopTransaction(transaction), next_transaction)
end


end -- of file
